<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2018/3/22
 * Time: 14:49
 */

namespace app\api\controller\v1;

use app\common\lib\exception\ApiException;
use think\Db;
use app\api\model\Lesson as LessonModel;
use think\Log;

class Lesson extends Common
{
    /**
     * @获取班级类型
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_class_type(){
        $class = (new LessonModel())->classType();
        return $class;
    }
    /**
     * @获取课程科目
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_subject(){
        $subject = (new LessonModel())->subject();
        return $subject;
    }
    /**
     * @获取课程项目
     * @subject_id int 必传
     * @author 巫玉梅 <1120504614@qq.com>
     */
    public function get_lesson_program(){
        $program = (new LessonModel())->lessonProgram();
        return $program;
    }
    /**
     * @获取课程服务目标
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_service_target(){
        $target = (new LessonModel())->serviceTarget();
        return $target;
    }
    /**
     * @获取课程风格
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_lesson_nature(){
        $nature = (new LessonModel())->lessonNature();
        return $nature;
    }

    /**
     * 获取课程的开课时间
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_start_lesson(){
        $result = (new LessonModel())->startLesson();
        return $result;
    }
    /**
     * @获取 年级
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function get_grade(){
        $grade = (new LessonModel())->grade();
        return $grade;
    }
    /**
     * 教师课程发布
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function save(){
        $lesson = (new LessonModel())->addLesson();
        return $lesson;
    }
    /**
     * 课程修改
     * @author 巫玉梅 <1120504614@qq.com>
     * @return ApiException|array|string|\think\response\Json
     */
    public function edit_lesson_info(){
        $lesson = (new LessonModel())->editLesson();
        return $lesson;
    }

    /**
     * 通过id查看课程信息/通过的课程号查询课程
     * @param id int 课程id/lesson_sn int  必传一个
     * @param is_approve int 是否审核 0待审核 1已审核 2已开课 默认为1
     * @param status int 通过id查询传1 课程号查询传2
     * @author 王柯 <wangke.email@foxmail.com>
     * @return array|string|\think\response\Json
     */
    public function read(){
        $lesson = (new LessonModel())->lessonDetails();
        return $lesson;
    }
    /**
     * 根据年级查询课程信息
     * @param grade_id int 年级id *必传
     * @param cost_type int 费用类型 1学费 2学币 *必传
     * @param page int 获取数据页码 不传默认为第一页
     * @param count int 每页显示条数不传默认为6条
     * @param is_approve int 是否审核 0待审核 1已审核 2已开课 默认为1
     * @param com_lesson_num int 完结课时数 不传默认为0 (未开课)
     * @author 王柯 <wangke.email@foxmail.com>
     * @return array|string|\think\response\Json
     */
    public function get_lesson_by_grade(){
        $lesson = (new LessonModel())->findLesson();
        return $lesson;
    }

    /**
     * 获取课程加载选项
     * @author 王柯 <wangke.email@foxmail.com>
     * @return array|string|\think\response\Json
     */
    public function get_lesson_option(){
        try{
            //获取班级类型
            $class_type = db('class')->select();

            //获取课程科目
            $subject = db('subject')->select();

            //获取课程服务目标
            $service_target = db('service_target')->select();

            //获取课程风格
            $lesson_nature = db('lesson_nature')->select();

            //获取教室信息
            $classroom = db('classroom')->select();

            //获取课程的开课时间
            $start_lesson_time = db('start_lesson')->select();

            $return = [
                'class_type' => $class_type,
                'subject' => $subject,
                'service_target' => $service_target,
                'lesson_nature' => $lesson_nature,
                'classroom' => $classroom,
                'start_lesson_time' => $start_lesson_time,
            ];

            return show(config('code.success'),'ok',$return);

        }catch(\Exception $e){
            Log::write($e->getMessage());
            return show(config('code.error'),$e->getMessage(),[],400);
        }
    }
}